<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <div id="app">
      <button @click="add">+</button>
      <button @click="sub">-</button>
      {{ $store.state.num }}
    </div>
    <script src="js/vue.js"></script>
    <script src="js/vuex.js"></script>
    <script>
      var store = new Vuex.Store({
        state: {
          num: 1
        },
        mutations: {
          add_num(state) {
            state.num++
          },
          sub_num(state) {
            state.num--
          }
        }
      })

      var vm = new Vue({
        el: '#app',
        store,
        methods: {
          add() {
            this.$store.commit('add_num')
          },
          sub() {
            this.$store.commit('sub_num')
          }
        }
      })
    </script>
  </body>
</html>
